<!--
 @description 经销商档案管理-经销商档案新建管理
 @fileName index.vue
 @author zengqiongying
 @created 2023/04/13 15:29:51
-->
<template>
  <div class="has-foot-pb">
    <div class="ctm-content-head-fixed">
      <SearchInput
        v-model="searchValue"
        placeholder="输入经销商编码/经销商名称"
        @search="onSearch"
        @clear="onClear"
        @cancel="onSearch"
      />
    </div>

    <div class="ctm-content-tabs-sticky">
      <qmp-tabs
        ref="qmpTabs"
        v-model:active="activeTab"
        animated
        lazy-render
        class="tab-nav-transparent"
        @change="tabOnChange"
      >
        <qmp-tab v-for="(tab, i) in tabs" :key="i" :title="tab.title" :name="tab.name">
          <List
            :ref="(el) => setListRef(el, tab.name)"
            class="customer-change-list"
            :search-value="searchValue"
            :type="tab.name"
            page-type="A"
          />
        </qmp-tab>
      </qmp-tabs>
    </div>
    <div class="ctm-content-foot">
      <div class="btn ctm-btn-main radius-larg" @click="onCreate">新建经销商档案</div>
    </div>
  </div>
</template>

<script lang="ts">
  import { toRefs, getCurrentInstance } from 'vue'
  import { useRouter, onBeforeRouteLeave } from 'vue-router'
  import { useStore } from 'vuex'
  import { CommonPage } from '../mixins/CommonPage'
  import SearchInput from '@/components/SearchInput/index.vue'
  import List from '../components/CustomerChangeList/List.vue'
  export default {
    name: 'DealerInfoNewArchive',
    components: { SearchInput, List },
    setup() {
      const $router = useRouter()
      const $store = useStore()
      const instance = getCurrentInstance()
      const { datas, onSearch, onClear, onCreate, tabOnChange, setListRef } = CommonPage(
        'dealerNewArchive',
        $router,
        $store,
        instance
      )
      onBeforeRouteLeave((to, from, next) => {
        const instanceName = instance?.type?.name
        if (to.name === 'Index') {
          $store.commit('routerKeep/removeCache', instanceName)
        } else {
          $store.commit('routerKeep/resetCache', instanceName)
        }
        next()
      })
      return {
        ...toRefs(datas),
        onSearch,
        onClear,
        onCreate,
        tabOnChange,
        setListRef
      }
    }
  }
</script>
<style lang="less" scoped>
  .customer-change-list {
    position: relative;
    padding: 0 14px;
  }
</style>
